﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Sakura.Games.StgFramework.Builder.UI
{
	/// <summary>
	/// “伤害类型编辑”对话框。
	/// </summary>
	public partial class DamageTypeEditWindow : Window
	{

		/// <summary>
		/// 获取或设置一个值，指示对话框的项目是否是新项目。
		/// </summary>
		public bool IsNewItem
		{
			get
			{
				return (bool)GetValue(IsNewItemProperty);
			}
			set
			{
				SetValue(IsNewItemProperty, value);
			}
		}

		/// <summary>
		/// 获取对话框中获得的结果。
		/// </summary>
		public DamageType NewItem
		{
			get
			{
				return new DamageType
				{
					Name = this.NameTextBox.Text.Trim(),
					Description = this.DescTextBox.Text.Trim()
				};
			}
		}

		/// <summary>
		/// 将用户界面的状态状态和指定的数据对象同步。
		/// </summary>
		/// <param name="item">要同步的数据。</param>
		public void SetItemData(DamageType item)
		{
			if (item != null)
			{
				this.NameTextBox.Text = item.Name;
				this.DescTextBox.Text = item.Description;
			}
		}

		/// <summary>
		/// 标识 <see cref="IsNewItem"/> 依赖项属性。
		/// </summary>
		public static readonly DependencyProperty IsNewItemProperty = DependencyProperty.Register("IsNewItem", typeof(bool), typeof(DamageTypeEditWindow), new UIPropertyMetadata(false));

		/// <summary>
		/// 初始化一个对话框的新实例。
		/// </summary>
		public DamageTypeEditWindow()
		{
			InitializeComponent();
		}

		private void OnSaveCanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = !string.IsNullOrWhiteSpace(this.NameTextBox.Text);
		}

		private void OnSaveExecuted(object sender, ExecutedRoutedEventArgs e)
		{
			this.DialogResult = true;
			this.Close();
		}

		private void OnCancelCanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = true;
		}

		private void OnCancelExecuted(object sender, ExecutedRoutedEventArgs e)
		{
			this.DialogResult = false;
			this.Close();
		}
	}
}
